/**
 * DownloadRequest.java
 */
package fss.common.communication;

import fss.transfer.TransferId;
import fss.transfer.TransferType;
import fss.util.rmi.RmiId;

/**
 * A download requset that a Remote File Service can process
 * to intantiate a downlaod between the service and the source
 * of this request.
 * 
 * @author thinh
 *
 */
public class DownloadRequest extends Request {
    private static final long serialVersionUID = 1L;
    /**
     * The transfer identifier.
     */
    private TransferId transferId = null;
    /**
     * The offset of the last downloaded data.
     */
    private long offset = 0;
    /**
     * Constructor for a download request.
     * @param sourceId the creator of this request.
     * @param transferId the transfer identifier.
     */
    public DownloadRequest(RmiId sourceId, TransferId transferId) {
        super(sourceId);
        if(transferId == null || transferId.getType() != TransferType.DOWNLOAD) {
            throw new IllegalArgumentException("Cannot recreate a Download Request with Transfer ID: " + transferId);
        }
        this.transferId = transferId;
    }
    /**
     * Get the transfer id.
     * @return the id.
     */
    public TransferId getTransferId() {
        return transferId;
    }
    /**
     * Set the transfer id.
     * @param transferId the id.
     */
    public void setTransferId(TransferId transferId) {
        this.transferId = transferId;
    }
    /**
     * The offset of the the last downloaded byte position.
     * <p>
     * If the offset is zero, then it indicates a new download request.
     * @return the offset.
     */
    public long getOffset() {
        return offset;
    }
    /**
     * Set the offset.
     * @param offset the offset byte position.
     */
    public void setOffset(long offset) {
        this.offset = offset;
    }
}
